﻿/*

 * @(#) DBProcException.java 1.0 2004-4-19

 * @author xingxiaojie

 *

 * Copyright 2003 by LongTop Corporation.

 * 10 Hubinbei Road, XiaMen, PRC 361012

 * All rights reserved.

 *

 * This software is the confidential and proprietary information of

 * LongTop Corporation ("Confidential Information").  You

 * shall not disclose such Confidential Information and shall use

 * it only in accordance with the terms of the license agreement

 * you entered into with LongTop.

 */

package net.comm.db;



import org.apache.log4j.Logger;





/**

 * @author 

 * @version 1.0

 * @creatime 2004-4-19

 */

public class DBProcException extends Exception {

	static Logger logger = Logger.getLogger(DBProcException.class.getName());
	

	/**

	 * 

	 */

	private static final long serialVersionUID = 2911453478374851022L;

	/**

	 * Default error code

	 */

	private String message = "netweb数据库处理异常错误";

	private int errcode=0;

	private Throwable subExcept;

	

	/**

	 * Default ErrormESSAGE

	 */

	public DBProcException() {



	}



	private String getMessageByCode(int errcode){

		//TODO get message from error message defined modul

		return message;

	}

	

	public int getErrorCode() {

		return errcode;

	}

	

	public String getMessage() {

		return message;

	}



	/**

	 * OutPrint ErrorMessage.

	 */

	public DBProcException(String anErrorMessage) {

		logger.debug("DBProcExcption"+"Make a new DBProcException");

		message=anErrorMessage;

	}

	

	public DBProcException(int aCode) {

		logger.debug("DBProcExcption"+"Make a new DBProcException");

		this.errcode=aCode;

	}

	

	public DBProcException(int aCode,String aMessage) {

		logger.debug("DBProcExcption"+"Make a new DBProcException");

		this.errcode=aCode;

		message=aMessage;

	}

	

	public DBProcException(Throwable except,int aCode) {

		logger.debug("DBProcExcption"+"Make a new DBProcException");

		errcode=aCode;

		subExcept=except;

	}



	public DBProcException(Throwable except,int aCode,String anErrMsg) {

		logger.debug("DBProcExcption"+"Make a new DBProcException");

		message=anErrMsg;

		subExcept=except;

		errcode=aCode;

	}

	

	public DBProcException(Throwable except,String anErrMsg) {

		logger.debug("DBProcExcption"+"Make a new DBProcException");

		message=anErrMsg;

		subExcept=except;

	}

	

	private Exception getException() {

		return (Exception)subExcept;

	}



	 /**

	  *the format to print the exception

	  */

	 public String toString()

	 {

	 	if(errcode!=0) {

	 		message=getMessageByCode(errcode);

	 	}

	 	

		 StringBuffer b = new StringBuffer();

		 b.append("DBProcException: ").append(message);

		 if(getException() != null)

			 b.append("[SubException:").append(getException()).append("]");

		 return b.toString();

	}

}

